//添加线下店铺

import React, { useState } from "react";
import { CommonModal } from "@/views/components/CommonModal";
import CommonLoading from "@/components/CommonLoading";
import { Input, Form, message, Radio } from "antd";
import { layout1 } from "@/utils/config";
import { saveOfflineStore } from "@/services/common";
import { useNavigate } from "react-router-dom";

export default ({ visible, handleVisible }) => {
	const [form] = Form.useForm();
	const [loading, setLoading] = useState(false);
	const navigate = useNavigate();
	const handleSubmit = async () => {
		setLoading(true);
		const { storeName, offlineExpressPlatform } = form.getFieldsValue();
		const res = await saveOfflineStore({
			storeName,
			offlineExpressPlatform,
			type: 0
		});
		setLoading(false);
		if (res.success) {
			message.success("添加成功！");
			navigate(0);
		}
	};

	const onOk = () => {
		form.validateFields().then(val => {
			handleSubmit();
		});
	};

	return (
		<CommonModal title={{ title: "编辑名称" }} visible={visible} onCancel={() => handleVisible(false)} onOk={onOk} width="600px">
			<Form {...layout1} form={form} name="add-offline-store">
				<Form.Item name="storeName" label="店铺" rules={[{ required: true, message: "店铺未填写" }]}>
					<Input placeholder="请输入店铺" />
				</Form.Item>
				<Form.Item label="面单获取平台" name="offlineExpressPlatform" rules={[{ required: true, message: "请选择面单获取平台" }]}>
					<Radio.Group>
						<Radio value={8}>淘宝</Radio>
						<Radio value={1}>京东</Radio>
						<Radio value={9}>拼多多</Radio>
					</Radio.Group>
				</Form.Item>
			</Form>
			<CommonLoading loading={loading} />
		</CommonModal>
	);
};
